<template>
    <div style="padding: 0 10px;">
        <div class="mobile-page paddingBox" :class="bgStyle === 0 ? '' : 'pageOn'"
            :style="{ marginTop: slider + 'px', background: activeColor }">
            <div class="home_product">
                <!-- 单列 -->
                <template v-if="itemStyle == 0">
                    <div class="header">
                        <div class="header_left">
                            <div style="height: 20px;width: 20px;background-color: #000000;border-radius: 50%;">
                                <img v-if="titleimage" :src="titleimage" style="height: 15px;width: 15px;margin: 2px;"
                                    alt="">
                                <div v-else class="el-icon-tickets"
                                    style="border-radius: 50%; color: #FFFFFF;line-height: 20px;margin-left: 2px;">
                                </div>
                            </div>
                            <div class="" style="font-weight: bolder;margin-left: 5px;">
                                {{ titleTxt ? titleTxt : '标题' }}
                            </div>
                        </div>
                        <div style="font-size: 10px;">
                            查看更多
                            <span class="el-icon-arrow-right"></span>
                        </div>
                    </div>
                    <div class="list-wrapper itemA" v-if="list.length > 0">
                        <div class="item" :class="conStyle ? '' : 'itemOn'" v-for="(item, index) in list" :index="index">
                            <div class="img-box">
                                <img v-if="item.image" :src="item.image" alt="">
                                <div v-else class="empty-box"><span class="iconfont-diy icontupian"></span></div>
                            </div>
                        </div>
                    </div>
                    <div class="list-wrapper itemA" v-else>
                        <div class="item" :class="conStyle ? '' : 'itemOn'">
                            <div class="info">
                                <div class="hd">
                                    <div class="item_title">内容标题</div>
                                </div>
                                <div style="font-size: 10px;color: #292929;">2024年1月12日</div>
                            </div>
                            <div class="img-box">
                                <div class="empty-box"><span class="iconfont-diy icontupian"></span></div>
                            </div>
                        </div>
                    </div>
                </template>
                <!-- 二列 -->
                <template v-if="itemStyle == 1">
                    <div class="header">
                        <div class="header_left">
                            <div style="height: 20px;width: 20px;background-color: #000000;border-radius: 50%;">
                                <img v-if="titleimage" :src="titleimage" style="height: 15px;width: 15px;margin: 2px;"
                                    alt="">
                                <div v-else class="el-icon-tickets"
                                    style="border-radius: 50%; color: #FFFFFF;line-height: 20px;margin-left: 2px;">
                                </div>
                            </div>
                            <div class="" style="font-weight: bolder;margin-left: 5px;">
                                {{ titleTxt ? titleTxt : '标题' }}
                            </div>
                        </div>
                        <div style="font-size: 10px;">
                            查看更多
                            <span class="el-icon-arrow-right"></span>
                        </div>
                    </div>
                    <div class="list-wrapper itemC" v-if="list.length > 0">
                        <div class="item" :class="conStyle ? '' : 'itemOn'" v-for="(item, index) in list" :index="index">
                            <div class="img-box">
                                <img v-if="item.image" :src="item.image" alt="">
                                <div v-else class="empty-box"><span class="iconfont-diy icontupian"></span></div>
                            </div>
                        </div>
                    </div>
                    <div class="list-wrapper" style="height: 220px;" v-else>
                        <div class="item" :class="conStyle ? '' : 'itemOn'">
                            <div class="img-box">
                                <div class="empty-box"><span class="iconfont-diy icontupian"></span></div>
                            </div>
                            <div class="info">
                                <div class="hd">
                                    <div class="title line2">内容标题</div>
                                </div>
                            </div>
                        </div>
                        <div class="item" :class="conStyle ? '' : 'itemOn'">
                            <div class="img-box">
                                <div class="empty-box"><span class="iconfont-diy icontupian"></span></div>
                            </div>
                            <div class="info">
                                <div class="hd">
                                    <div class="title line2">内容标题</div>
                                </div>
                            </div>
                        </div>
                    </div>
                </template>
            </div>
        </div>
    </div>
</template>

<script>
import { mapState } from 'vuex'
export default {
    name: 'home_seek',
    cname: '内容列表',
    configName: 'c_home_seek',
    icon: 'iconshangpinliebiao2',
    type: 0, // 0 基础组件 1 营销组件 2工具组件
    defaultName: 'seekList', // 外面匹配名称
    props: {
        index: {
            type: null
        },
        num: {
            type: null
        }
    },
    computed: {
        ...mapState('mobildConfig', ['defaultArray'])
    },
    watch: {
        pageData: {
            handler(nVal, oVal) {
                this.setConfig(nVal)
            },
            deep: true
        },
        num: {
            handler(nVal, oVal) {
                let data = this.$store.state.mobildConfig.defaultArray[nVal]
                this.setConfig(data)
            },
            deep: true
        },
        'defaultArray': {
            handler(nVal, oVal) {
                let data = this.$store.state.mobildConfig.defaultArray[this.num]
                this.setConfig(data);
            },
            deep: true
        }
    },
    data() {
        return {

            // 默认初始化数据禁止修改
            defaultConfig: {
                name: 'seekList',
                timestamp: this.num,
                setUp: {
                    tabVal: '0'
                },
                swiperConfig: {
                    maxList: 1,
                    list: [
                        {
                            img: "",
                            info: [
                                {
                                    title: "标题",
                                    value: "今日推荐",
                                    tips: "选填，不超过4个字",
                                    max: 4,
                                },
                                {
                                    title: "链接",
                                    value: "",
                                    tips: "请输入链接",
                                    max: 100,
                                },
                            ],
                        },
                    ],
                },
                numConfig: {
                    title: '内容数量',
                    val: 2
                },
                selectConfig: {
                    title: '栏目分类',
                    name:'selectConfig',
                    activeValue: [],
                    list: [
                        {
                            value: 'value1',
                            label: 'label1'
                        },
                        {
                            value: 'value2',
                            label: 'label2'
                        }
                    ]
                },
                themeColor: {
                    title: '背景颜色',
                    name: 'themeColor',
                    default: [{
                        item: '#fff'
                    }],
                    color: [
                        {
                            item: '#fff'
                        }
                    ]
                },
                itemStyle: {
                    title: '显示类型',
                    name: 'itemSstyle',
                    type: 0,
                    list: [
                        {
                            val: '单列',
                            icon: 'iconzuoyoutuwen'
                        },
                        {
                            val: '两列',
                            icon: 'iconlianglie'
                        },
                    ]
                },
                bgStyle: {
                    title: '背景样式',
                    name: 'bgStyle',
                    type: 0,
                    list: [
                        {
                            val: '直角',
                            icon: 'iconPic_square'
                        },
                        {
                            val: '圆角',
                            icon: 'iconPic_fillet'
                        }
                    ]
                },
                conStyle: {
                    title: '内容样式',
                    name: 'conStyle',
                    type: 1,
                    list: [
                        {
                            val: '直角',
                            icon: 'iconPic_square'
                        },
                        {
                            val: '圆角',
                            icon: 'iconPic_fillet'
                        }
                    ]
                },
                mbConfig: {
                    title: '页面间距',
                    val: 0,
                    min: 0
                },
            },
            navlist: [],
            imgStyle: '',
            txtColor: '',
            slider: '',
            tabCur: 0,
            list: [],
            activeColor: '',
            pageData: {},
            itemStyle: 0,
            bgStyle: 0,
            conStyle: 1,
            titleTxt: '',
            titleimage: '',
        }
    },
    mounted() {
        this.$nextTick(() => {
            this.pageData = this.$store.state.mobildConfig.defaultArray[this.num]
            this.setConfig(this.pageData)
        })
    },
    methods: {
        setConfig(data) {
            if (!data) return
            if (data.mbConfig) {
                this.titleTxt = data.swiperConfig.list[0].info[0].value
                this.titleimage = data.swiperConfig.list[0].img
                this.itemStyle = data.itemStyle.type || 0;
                this.activeColor = data.themeColor.color[0].item;
                this.slider = data.mbConfig.val;
                this.bgStyle = data.bgStyle.type;
                this.conStyle = data.conStyle.type;
            }
        }
    }
}
</script>
<style scoped lang="scss">
.item_title {
    font-size: 13px;
    font-weight: bolder;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
}

.header {
    height: 25px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-top: 10px;

    .header_left {
        display: flex;
        align-items: center;
        height: 25px;
    }
}

.itemOn {
    border-radius: 0 !important;

    img,
    .empty-box {
        border-radius: 0 !important;
    }

    .img-box {
        .label {
            border-radius: 0 0 8px 0 !important;
        }
    }
}

.pageOn {
    border-radius: 8px !important;
}

.line2 {
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
}

.listBig {
    width: 100%;
    padding: 10px 0 10px 0;

    .itemBig {
        width: 100%;
        margin-bottom: 15px;
        border-radius: 10px;

        .img-box {
            width: 100%;
            height: 160px;
            position: relative;
            border-radius: 50px;

            img {
                width: 100%;
                height: 160px;
                border-radius: 10px;
            }

            .empty-box {
                border-radius: 8px 8px 0 0;
            }

            .label {
                position: absolute;
                top: 0;
                left: 0;
                width: 59px;
                height: 25px;
                line-height: 25px;
                text-align: center;
                color: #fff;
                font-size: 12px;
                border-radius: 8px 0 8px 0;
            }
        }

        .name {
            font-size: 15px;
            font-weight: bold;
            margin-top: 8px;
            padding: 0 10px;
        }

        .coupon {
            width: 16px;
            height: 18px;
            line-height: 18px;
            text-align: center;
            font-size: 12px;
            margin-right: 5px;
            display: inline-block;
        }

        .price {
            font-weight: bold;
            font-size: 12px;
            padding: 0 10px;
            margin-top: 10px;

            .num {
                font-size: 18px;
                margin-right: 5px;
            }

            .old-price {
                color: #aaa !important;
                font-weight: normal;
                text-decoration: line-through;
            }
        }
    }
}

.paddingBox {
    padding-bottom: 0;
}

.home_product {
    .hd_nav {
        display: flex;
        height: 65px;
        padding: 0 5px;

        .item {
            display: flex;
            flex-direction: column;
            justify-content: center;
            width: 25%;

            .title {
                font-size: 16px;
                color: #282828;
            }

            .label {
                width: 62px;
                height: 18px;
                line-height: 18px;
                text-align: center;
                background: transparent;
                border-radius: 8px;
                color: #999999;
                font-size: 12px;

                &.active {
                    .title {
                        color: #FF4444;
                    }

                    .label {
                        color: #fff;
                        background: linear-gradient(270deg, rgba(255, 84, 0, 1) 0%, rgba(255, 0, 0, 1) 100%);
                    }
                }

            }
        }
    }

    .list-wrapper {
        display: flex;
        flex-wrap: wrap;
        justify-content: space-between;
        padding-top: 5px;

        .item {
            width: 48.5%;
            margin-bottom: 10px;
            border-radius: 10px;

            .img-box {
                position: relative;
                width: 100%;
                height: 173px;

                img,
                .box {
                    width: 100%;
                    height: 100%;
                    border-radius: 10px 0 0 10px;
                }

                .empty-box {
                    background: #f3f5f7;
                    border-radius: 10px;
                }

                .box {
                    background: #D8D8D8;
                }
            }

            .info {
                padding: 15px 10px;
                overflow: hidden;

                .title {
                    font-size: 14px;
                    color: #282828;
                    height: 28px;
                }

                .text {
                    display: flex;
                    align-items: center;
                    margin-top: 10px;
                }

                .label {
                    padding: 0 5px;
                    border-radius: 2px;
                    color: #fff;
                    font-size: 10px;
                    text-align: center;
                    line-height: 15px;
                }

                .coupon,
                .ship {
                    padding: 0 5px;
                    line-height: 13px;
                    border-radius: 2px;
                    font-size: 10px;
                    margin-left: 3px;
                }

                .ship {
                    color: #FF9000;
                    border: 1px solid #FF9000;
                }

                .old-price {
                    color: #aaa;
                    font-size: 13px;
                    text-decoration: line-through;
                    margin-left: 3px;
                }

                .price {
                    display: flex;
                    align-items: center;

                    .num {
                        font-size: 14px;

                        span {
                            font-size: 14px;
                        }
                    }

                    .label {
                        width: 16px;
                        height: 18px;
                        margin-left: 5px;
                        text-align: center;
                        line-height: 18px;
                        font-size: 11px;

                        &.on {
                            margin-left: 0;
                        }
                    }
                }
            }
        }

        &.itemA

        /*background #fff*/
        .item {
            display: flex;
            width: 100%;

            .img-box {
                position: relative;
                width: 110px;
                height: 110px;

                img,
                .box,
                .empty-box {
                    border-radius: 10px;
                }
            }

            .info {
                display: flex;
                justify-content: space-between;
                flex-direction: column;
                flex: 1;
                // margin-left: 5px;
                padding: 5px 10px;

                .num {
                    font-weight: bold;
                }
            }
        }

        &.itemB {
            justify-content: inherit;

            .item {
                width: 31.6%;
                margin-right: 8px;

                &:nth-child(3n) {
                    margin-right: 0;
                }

                .img-box {
                    position: relative;
                    width: 100%;
                    height: 110px;

                    img,
                    .box,
                    .empty-box {
                        border-radius: 10px 10px 0 0;
                    }
                }
            }
        }

        &.itemC {
            .item {
                background-color: #fff;

                img,
                .box,
                .empty-box {
                    border-radius: 10px 10px 0 0;
                }

                .price {
                    margin-top: 10px;
                }
            }
        }
    }
}
</style>
